<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        .user-profile {
            margin-top: 20px;
        }
    </style>
    <title>个人信息</title>
</head>
<body>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <a class="navbar-brand" href="/index.html">首页</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
            aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item">
                <a class="nav-link" href="/adopt.html">我的领养</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/person.html">个人信息</a>
            </li>
        </ul>
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="/logout">退出</a>
            </li>
        </ul>
    </div>
</nav>

<div class="container user-profile">
    <h2>个人信息</h2>
    <form action="/person/update" method="post">
        <input type="text" class="form-control" id="id" name="id" hidden>
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" class="form-control" id="username" name="username" placeholder="输入用户名" value="" readonly>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" name="password" placeholder="输入密码">
        </div>
        <div class="form-group">
            <label for="tel">联系方式</label>
            <input type="tel" class="form-control" id="tel" name="tel" placeholder="输入联系方式" value="">
        </div>
        <div class="form-group">
            <label for="gender">性别</label>
            <select class="form-control" name="gender" id="gender">
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
        <div class="form-group">
            <label for="address">地址</label>
            <textarea class="form-control" name="address" id="address" rows="3" placeholder="输入地址"></textarea>
        </div>
        <button type="submit" class="btn btn-primary">保存修改</button>
    </form>
</div>

<script src="/js/jquery.min.js"></script>
<script>
    $.ajax({
        url: '/person/info',
        method: 'GET',
        success: function (data) {
            $("#id").val(data.id);
            $("#username").val(data.username);
            $("#password").val(data.password);
            $("#tel").val(data.tel);
            $("#gender").val(data.gender);
            $("#address").val(data.address);
        },
        error: function (error) {
            console.error('出错:', error);
        }
    });
</script>

</body>
</html>
